package nc.ui.arap.report.page;

import nc.vo.arap.pub.QueryStructVO;
import nc.vo.arap.pub.report.PaginationConfig;
import nc.vo.arap.pub.report.SimplePaginationConfig;

public abstract class PaginationUtils {
	
	public static PaginationConfig initPaginationConfig(PaginationConfig paginationConfig, QueryStructVO queryStructVO) {
		if (paginationConfig == null) {
			paginationConfig = new SimplePaginationConfig();
		}
		PageSizeStrategy pageSizeStrategy = null;
		if (queryStructVO.getQueryTypeInfo().isMaxNumberPaged()) {
			pageSizeStrategy = new LineStylePageSizeStrategy();
		} else {
			pageSizeStrategy = new QryObjStylePageSizeStrategy();
		}
		paginationConfig.setPageSize(pageSizeStrategy.getPageSize(queryStructVO));

		paginationConfig.setPageIndex(1);
		if (queryStructVO.getCorp().length == 1) {
			paginationConfig.setPageField(queryStructVO.getVetQryObj().get(0).getFldorigin() 
					+ "." + queryStructVO.getVetQryObj().get(0).getQryfld());
			paginationConfig.setTableAbbr(queryStructVO.getVetQryObj().get(0).getFldorigin());
			paginationConfig.setTableField(queryStructVO.getVetQryObj().get(0).getQryfld());
			paginationConfig.setFirst(true);
			paginationConfig.setPageFieldAlias(queryStructVO.getVetQryObj().get(0).getFldorigin() 
					+ "_" + queryStructVO.getVetQryObj().get(0).getQryfld());
		} else {
			paginationConfig.setPageField("zb.dwbm");
			paginationConfig.setTableAbbr("zb");
			paginationConfig.setTableField("dwbm");
			paginationConfig.setFirst(true);
			paginationConfig.setPageFieldAlias("zb_dwbm");
		}
		
		return paginationConfig;
//		return null;
	}

}
